package com.design.decorator;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ytj
 * @date 2024/11/27 17:26
 */
@Slf4j
public class LoginSsoDecorator extends SsoDecorator{
    private static Map<String,String> authMap=new ConcurrentHashMap<>();

    static {
        authMap.put("huahua","queryUserInfo");
        authMap.put("doudou","queryUserInfo");
    }

    public LoginSsoDecorator(HandleInterceptor handleInterceptor){
        super(handleInterceptor);
    }

    @Override
    public boolean preHandle(String request, String response, Object handle) {
        boolean preHandle = super.preHandle(request, response, handle);
        if(!preHandle){
            return false;
        }
        String userId=request.substring(8);
        String method=authMap.get(userId);
        log.info("模拟单点登录方法模拟登录校验:{},{}",userId,method);
        return "queryUserInfo".equals(method);
    }
}
